<template>
  <div class="dashboard">
    <div class="dashboard-header">
      <h1 class="dashboard-title">管理后台</h1>
      <p class="dashboard-subtitle">系统运行概览</p>
    </div>

    <!-- 统计卡片 -->
    <div class="stats-container">
      <div class="stat-card primary">
        <div class="stat-icon">
          <i class="fa fa-file-text-o"></i>
        </div>
        <div class="stat-info">
          <h3 class="stat-label">总工单数</h3>
          <p class="stat-value">128</p>
        </div>
        <div class="stat-trend positive">
          <i class="fa fa-arrow-up"></i>
          <span>12%</span>
        </div>
      </div>

      <div class="stat-card success">
        <div class="stat-icon">
          <i class="fa fa-check-circle-o"></i>
        </div>
        <div class="stat-info">
          <h3 class="stat-label">已完成</h3>
          <p class="stat-value">96</p>
        </div>
        <div class="stat-trend positive">
          <i class="fa fa-arrow-up"></i>
          <span>8%</span>
        </div>
      </div>

      <div class="stat-card warning">
        <div class="stat-icon">
          <i class="fa fa-clock-o"></i>
        </div>
        <div class="stat-info">
          <h3 class="stat-label">处理中</h3>
          <p class="stat-value">24</p>
        </div>
        <div class="stat-trend negative">
          <i class="fa fa-arrow-down"></i>
          <span>3%</span>
        </div>
      </div>

      <div class="stat-card danger">
        <div class="stat-icon">
          <i class="fa fa-exclamation-circle"></i>
        </div>
        <div class="stat-info">
          <h3 class="stat-label">紧急</h3>
          <p class="stat-value">8</p>
        </div>
        <div class="stat-trend negative">
          <i class="fa fa-arrow-up"></i>
          <span>1%</span>
        </div>
      </div>
    </div>

    <!-- 主要内容区域 -->
    <div class="main-content-grid">
      <!-- 图表区域 -->
      <div class="chart-section card">
        <div class="card-header">
          <h2 class="card-title">工单趋势</h2>
          <div class="card-actions">
            <button class="btn btn-sm">月</button>
            <button class="btn btn-sm active">周</button>
            <button class="btn btn-sm">日</button>
          </div>
        </div>
        <div class="card-body">
          <div class="chart-placeholder">
            <div class="chart-container">
              <!-- 模拟图表 -->
              <div class="chart-bars">
                <div class="chart-bar" style="height: 70%"></div>
                <div class="chart-bar" style="height: 40%"></div>
                <div class="chart-bar" style="height: 60%"></div>
                <div class="chart-bar" style="height: 80%"></div>
                <div class="chart-bar" style="height: 50%"></div>
                <div class="chart-bar" style="height: 90%"></div>
                <div class="chart-bar" style="height: 65%"></div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 最近活动 -->
      <div class="activity-section card">
        <div class="card-header">
          <h2 class="card-title">最近活动</h2>
          <div class="card-actions">
            <button class="btn btn-link">查看全部</button>
          </div>
        </div>
        <div class="card-body">
          <ul class="activity-list">
            <li class="activity-item">
              <div class="activity-user-avatar">
                <img src="https://picsum.photos/id/1007/40/40" alt="用户头像">
              </div>
              <div class="activity-details">
                <p class="activity-text"><strong>张三</strong> 创建了新工单 #1001</p>
                <p class="activity-time">2分钟前</p>
              </div>
              <div class="activity-status success">
                <i class="fa fa-plus-circle"></i>
              </div>
            </li>
            <li class="activity-item">
              <div class="activity-user-avatar">
                <img src="https://picsum.photos/id/1008/40/40" alt="用户头像">
              </div>
              <div class="activity-details">
                <p class="activity-text"><strong>李四</strong> 完成了工单 #998</p>
                <p class="activity-time">15分钟前</p>
              </div>
              <div class="activity-status success">
                <i class="fa fa-check"></i>
              </div>
            </li>
            <li class="activity-item">
              <div class="activity-user-avatar">
                <img src="https://picsum.photos/id/1009/40/40" alt="用户头像">
              </div>
              <div class="activity-details">
                <p class="activity-text"><strong>王五</strong> 评论了工单 #1000</p>
                <p class="activity-time">30分钟前</p>
              </div>
              <div class="activity-status info">
                <i class="fa fa-comment"></i>
              </div>
            </li>
            <li class="activity-item">
              <div class="activity-user-avatar">
                <img src="https://picsum.photos/id/1010/40/40" alt="用户头像">
              </div>
              <div class="activity-details">
                <p class="activity-text"><strong>赵六</strong> 更新了工单 #1002 状态</p>
                <p class="activity-time">1小时前</p>
              </div>
              <div class="activity-status warning">
                <i class="fa fa-refresh"></i>
              </div>
            </li>
            <li class="activity-item">
              <div class="activity-user-avatar">
                <img src="https://picsum.photos/id/1011/40/40" alt="用户头像">
              </div>
              <div class="activity-details">
                <p class="activity-text"><strong>钱七</strong> 分配了工单 #1003 给你</p>
                <p class="activity-time">2小时前</p>
              </div>
              <div class="activity-status danger">
                <i class="fa fa-exclamation"></i>
              </div>
            </li>
          </ul>
        </div>
      </div>
    </div>

    <!-- 快捷操作 -->
    <div class="quick-actions card">
      <div class="card-header">
        <h2 class="card-title">快捷操作</h2>
      </div>
      <div class="card-body">
        <div class="quick-actions-grid">
          <button class="quick-action-btn">
            <i class="fa fa-user-plus"></i>
            <span>添加用户</span>
          </button>
          <button class="quick-action-btn">
            <i class="fa fa-list-alt"></i>
            <span>创建工单</span>
          </button>
          <button class="quick-action-btn">
            <i class="fa fa-bar-chart"></i>
            <span>生成报告</span>
          </button>
          <button class="quick-action-btn">
            <i class="fa fa-cog"></i>
            <span>系统设置</span>
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
</script>

<style scoped>
.dashboard {
  padding: 1.5rem;
  background-color: #f5f7fa;
  min-height: 100%;
}

.dashboard-header {
  margin-bottom: 1.5rem;
}

.dashboard-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 0.25rem;
}

.dashboard-subtitle {
  font-size: 1rem;
  color: #64748b;
}

/* 统计卡片样式 */
.stats-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: white;
  border-radius: 0.75rem;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  transition: transform 0.2s, box-shadow 0.2s;
  border-left: 4px solid #cbd5e1;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
}

.stat-card.primary {
  border-left-color: #3b82f6;
}

.stat-card.success {
  border-left-color: #10b981;
}

.stat-card.warning {
  border-left-color: #f59e0b;
}

.stat-card.danger {
  border-left-color: #ef4444;
}

.stat-icon {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 1rem;
  font-size: 1.5rem;
  background-color: #f1f5f9;
  color: #64748b;
}

.stat-card.primary .stat-icon {
  background-color: #dbeafe;
  color: #3b82f6;
}

.stat-card.success .stat-icon {
  background-color: #dcfce7;
  color: #10b981;
}

.stat-card.warning .stat-icon {
  background-color: #fef3c7;
  color: #f59e0b;
}

.stat-card.danger .stat-icon {
  background-color: #fee2e2;
  color: #ef4444;
}

.stat-info {
  flex: 1;
}

.stat-label {
  font-size: 0.875rem;
  color: #64748b;
  margin-bottom: 0.25rem;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: #1e293b;
  margin: 0;
}

.stat-trend {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: 0.875rem;
  font-weight: 600;
}

.stat-trend.positive {
  color: #10b981;
}

.stat-trend.negative {
  color: #ef4444;
}

/* 卡片通用样式 */
.card {
  background: white;
  border-radius: 0.75rem;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
  margin-bottom: 1.5rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem 0.75rem;
  border-bottom: 1px solid #e2e8f0;
}

.card-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: #1e293b;
  margin: 0;
}

.card-actions {
  display: flex;
  gap: 0.5rem;
}

.card-body {
  padding: 1.5rem;
}

/* 按钮样式 */
.btn {
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  background-color: #e2e8f0;
  color: #475569;
  transition: all 0.2s;
}

.btn:hover {
  background-color: #cbd5e1;
}

.btn.active {
  background-color: #3b82f6;
  color: white;
}

.btn-sm {
  padding: 0.25rem 0.75rem;
  font-size: 0.8125rem;
}

.btn-link {
  background: none;
  border: none;
  color: #3b82f6;
  text-decoration: underline;
}

.btn-link:hover {
  background: none;
  color: #2563eb;
}

/* 图表样式 */
.chart-placeholder {
  height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #f8fafc;
  border-radius: 0.5rem;
}

.chart-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 1rem;
  gap: 1rem;
}

.chart-bars {
  display: flex;
  align-items: flex-end;
  height: 80%;
  gap: 1rem;
}

.chart-bar {
  width: 30px;
  background: linear-gradient(to top, #3b82f6, #93c5fd);
  border-radius: 4px 4px 0 0;
  position: relative;
}

.chart-bar:before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(to right, rgba(255,255,255,0.2), rgba(255,255,255,0));
  border-radius: 4px 4px 0 0;
}

/* 活动列表样式 */
.activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.activity-item {
  display: flex;
  align-items: center;
  padding: 1rem 0;
  border-bottom: 1px solid #e2e8f0;
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-user-avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  overflow: hidden;
  margin-right: 1rem;
  flex-shrink: 0;
}

.activity-user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.activity-details {
  flex: 1;
  min-width: 0;
}

.activity-text {
  font-size: 0.9375rem;
  color: #1e293b;
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.activity-text strong {
  font-weight: 600;
}

.activity-time {
  font-size: 0.8125rem;
  color: #94a3b8;
}

.activity-status {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-left: 1rem;
  color: white;
  font-size: 0.875rem;
}

.activity-status.success {
  background-color: #10b981;
}

.activity-status.info {
  background-color: #3b82f6;
}

.activity-status.warning {
  background-color: #f59e0b;
}

.activity-status.danger {
  background-color: #ef4444;
}

/* 快捷操作样式 */
.quick-actions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
}

.quick-action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
  border-radius: 0.75rem;
  background-color: #f1f5f9;
  border: 1px solid #e2e8f0;
  cursor: pointer;
  transition: all 0.2s;
}

.quick-action-btn:hover {
  background-color: #e2e8f0;
  transform: translateY(-2px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.quick-action-btn i {
  font-size: 1.5rem;
  margin-bottom: 0.75rem;
  color: #64748b;
}

.quick-action-btn span {
  font-size: 0.9375rem;
  color: #475569;
  font-weight: 500;
}

/* 主内容网格布局 */
.main-content-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .dashboard {
    padding: 1rem;
  }
  
  .stats-container {
    grid-template-columns: 1fr 1fr;
  }
  
  .main-content-grid {
    grid-template-columns: 1fr;
  }
  
  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
  
  .card-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

@media (max-width: 480px) {
  .stats-container {
    grid-template-columns: 1fr;
  }
  
  .dashboard-title {
    font-size: 1.5rem;
  }
  
  .stat-value {
    font-size: 1.5rem;
  }
}
</style>